package ink.xiaobaibai.bo;

import com.alibaba.fastjson.JSON;
import ink.xiaobaibai.emqtt.EMqttManager;
import ink.xiaobaibai.emqtt.EMqttService;
import ink.xiaobaibai.emqtt.MyMqttCallback;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * @description: 机器启动所需的时间参数
 * @author: 小白白
 * @create: 2021-06-08
 **/

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeviceMqttBo {

    public DeviceMqttBo(String deviceCode, Boolean isOpen, Integer startDelayedTime, Integer fanTime, Integer valveTime, Integer workTime) {
        this.deviceCode = deviceCode;
        this.isOpen = isOpen;
        this.startDelayedTime = startDelayedTime;
        this.fanTime = fanTime;
        this.valveTime = valveTime;
        this.workTime = workTime;
    }

    public DeviceMqttBo(String deviceCode, Boolean isOpen) {
        this.deviceCode = deviceCode;
        this.isOpen = isOpen;
    }

    public DeviceMqttBo(String deviceCode, Boolean isOpen, String roomNumber) {
        this.deviceCode = deviceCode;
        this.isOpen = isOpen;
        this.roomNumber = roomNumber;
    }

    /**
     * 机器码
     */
    private String deviceCode;
    /**
     * 是否启动
     */
    private Boolean isOpen;
    /**
     * 启动延时(秒)
     */
    private Integer startDelayedTime;

    /**
     * 风扇继续时间(秒)
     */
    private Integer fanTime;

    /**
     * 阀门继续时间(秒)
     */
    private Integer valveTime;

    /**
     * 工作时间(秒)
     */
    private Integer workTime;

    /**
     * 房间号(免费机器专用)
     */
    private String roomNumber;

    public static void main(String[] args) {
        DeviceMqttBo deviceMqttBo = new DeviceMqttBo("code_12345", true, 10, 10, 10, 10);
        EMqttService clientTest = EMqttManager.getClientTest("yytest", "yytest", "clientId", new MyMqttCallback() {
            @Override
            protected void connectionLost2(Throwable throwable) {

            }

            @Override
            protected void messageArrived2(String s, MqttMessage mqttMessage) {
                String s1 = new String(mqttMessage.getPayload());
                System.out.println(s1);
            }

            @Override
            protected void deliveryComplete2(IMqttDeliveryToken iMqttDeliveryToken) {

            }
        });
        clientTest.start();
        clientTest.pushMessage(JSON.toJSONString(deviceMqttBo));
    }

}
